//
//  ClassRightCell.m
//  DiningCar-Business
//
//  Created by 吕晶 on 2020/4/13.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "ClassRightCell.h"

@interface ClassRightCell ()

@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UIImageView *imgView;//商品图片
@property (nonatomic, strong) UILabel *nameLab;//商品名称
@property (nonatomic, strong) UILabel *kuCunLab;//库存
@property (nonatomic, strong) UILabel *priceLab;//价格
@property (nonatomic, strong) UIButton *addBtn;//添加
@property (nonatomic, strong) UILabel *countLab;//数量
@property (nonatomic, strong) UIButton *reduceBtn;//减少

@end

@implementation ClassRightCell

+ (instancetype)ClassRightCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"ClassRightCell";
    ClassRightCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[ClassRightCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = HexColor(0xF0F2F5);
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.height = 92;
        
        self.bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, ScreenW - 90 - 20, 92)];
        self.bgView.backgroundColor = HexColor(0xffffff);
        [self addSubview:self.bgView];
        
        self.imgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 72, 72)];
        self.imgView.backgroundColor = HexColor(0xF0F2F5);
        self.imgView.layer.cornerRadius = 6;
        [self.bgView addSubview:self.imgView];
        
        self.nameLab = [[UILabel alloc] initWithFrame:CGRectMake(self.imgView.nim_right + 10, self.imgView.nim_top, self.bgView.nim_width - (self.imgView.nim_right + 10) - 10, 18)];
        self.nameLab.textColor = HexColor(0x3D3E5A);
        self.nameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.nameLab];
        
        self.kuCunLab = [[UILabel alloc] initWithFrame:CGRectMake(self.nameLab.nim_left, self.nameLab.nim_bottom + 5, self.nameLab.nim_width, 13)];
        self.kuCunLab.textColor = HexColor(0x3D3E5A);
        self.kuCunLab.font = [UIFont systemFontOfSize:12];
        [self.bgView addSubview:self.kuCunLab];
        
        self.priceLab = [[UILabel alloc] initWithFrame:CGRectMake(self.kuCunLab.nim_left, self.imgView.nim_bottom - 18, self.bgView.nim_width - 10 - 24 - 40 - 24 - 10 - self.kuCunLab.nim_left, 18)];
        self.priceLab.textColor = HexColor(0xFB4E44);
        self.priceLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.priceLab];
        
        self.addBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.bgView.nim_width - 10 - 24, self.imgView.nim_bottom - 24, 24, 24)];
        [self.addBtn setImage:[UIImage imageNamed:@"cashier_icon_add"] forState:0];
        [self.addBtn setImage:[UIImage imageNamed:@"cashier_icon_add"] forState:1];
        [self.bgView addSubview:self.addBtn];
        
        self.countLab = [[UILabel alloc] initWithFrame:CGRectMake(self.addBtn.nim_left - 40, self.addBtn.nim_top + 3, 40, 18)];
        self.countLab.textColor = HexColor(0x3D3E5A);
        self.countLab.font = BoldFontOfSize(16);
        self.countLab.textAlignment = NSTextAlignmentCenter;
        [self.bgView addSubview:self.countLab];
        
        self.reduceBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.countLab.nim_left - 24, self.imgView.nim_bottom - 24, 24, 24)];
        [self.reduceBtn setImage:[UIImage imageNamed:@"cashier_icon_reduce"] forState:0];
        [self.reduceBtn setImage:[UIImage imageNamed:@"cashier_icon_reduce"] forState:1];
        [self.bgView addSubview:self.reduceBtn];
        
    }
    return self;
}

-(void)setGoodModel:(CashierClassGoodModel *)goodModel {
    _goodModel = goodModel;
    self.nameLab.text = goodModel.title;
    self.kuCunLab.text = [NSString stringWithFormat:@"库存：%@",goodModel.last_amount];
    self.priceLab.text = [NSString stringWithFormat:@"¥%@",goodModel.price];
    self.countLab.text = [NSString stringWithFormat:@"%d",goodModel.count];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
